using IrisGenerator.Common.Tools;
namespace IrisGenerator.Common.Modules
{
    
    
    public partial class OptionInstance {
        
        private System.Nullable<System.Guid> _optInsId;
        
        private System.Nullable<System.Guid> _optId;
        
        private System.Nullable<System.Guid> _modInsId;
        
        private System.Nullable<System.Guid> _optInsValue;
        
        private ModuleInstance _moduleInstance;
        
        private Option _option;
        
        public virtual System.Nullable<System.Guid> OptInsId {
            get {
                return _optInsId;
            }
            set {
                _optInsId = value;
            }
        }
        
        public virtual System.Nullable<System.Guid> OptInsValue {
            get {
                return _optInsValue;
            }
            set {
                _optInsValue = value;
            }
        }
        
        public virtual ModuleInstance ModuleInstance {
            get {
                if ((this._moduleInstance == null)) {
                    this._moduleInstance = ModuleInstance.Load(this._modInsId);
                }
                return this._moduleInstance;
            }
            set {
                _moduleInstance = value;
            }
        }
        
        public virtual Option Option {
            get {
                if ((this._option == null)) {
                    this._option = Option.Load(this._optId);
                }
                return this._option;
            }
            set {
                _option = value;
            }
        }
        
        private void Clean() {
            this.OptInsId = null;
            this._optId = null;
            this._modInsId = null;
            this.OptInsValue = null;
            this.ModuleInstance = null;
            this.Option = null;
        }
        
        private void Fill(System.Data.DataRow dr) {
            this.Clean();
            if ((dr["OPT_INS_ID"] != System.DBNull.Value)) {
                this.OptInsId = ((System.Nullable<System.Guid>)(dr["OPT_INS_ID"]));
            }
            if ((dr["OPT_ID"] != System.DBNull.Value)) {
                this._optId = ((System.Nullable<System.Guid>)(dr["OPT_ID"]));
            }
            if ((dr["MOD_INS_ID"] != System.DBNull.Value)) {
                this._modInsId = ((System.Nullable<System.Guid>)(dr["MOD_INS_ID"]));
            }
            if ((dr["OPT_INS_VALUE"] != System.DBNull.Value)) {
                this.OptInsValue = ((System.Nullable<System.Guid>)(dr["OPT_INS_VALUE"]));
            }
        }
        
        public static OptionInstanceCollection Select_OPTION_INSTANCE_By_MOD_INS_ID(System.Nullable<System.Guid> MOD_INS_ID) {
            IrisGenerator.Dal.OptionInstance dbo = null;
            try {
                dbo = new IrisGenerator.Dal.OptionInstance();
                System.Data.DataSet ds = dbo.Select_OPTION_INSTANCE_By_MOD_INS_ID(MOD_INS_ID);
                OptionInstanceCollection collection = new OptionInstanceCollection();
                if (GlobalTools.IsSafeDataSet(ds)) {
                    for (int i = 0; (i < ds.Tables[0].Rows.Count); i = (i + 1)) {
                        OptionInstance obj = new OptionInstance();
                        obj.Fill(ds.Tables[0].Rows[i]);
                        if ((obj != null)) {
                            collection.Add(obj);
                        }
                    }
                }
                return collection;
            }
            catch (System.Exception ) {
                throw;
            }
            finally {
                if ((dbo != null)) {
                    dbo.Dispose();
                }
            }
        }
        
        public static OptionInstanceCollection Select_OPTION_INSTANCE_By_OPT_ID(System.Nullable<System.Guid> OPT_ID) {
            IrisGenerator.Dal.OptionInstance dbo = null;
            try {
                dbo = new IrisGenerator.Dal.OptionInstance();
                System.Data.DataSet ds = dbo.Select_OPTION_INSTANCE_By_OPT_ID(OPT_ID);
                OptionInstanceCollection collection = new OptionInstanceCollection();
                if (GlobalTools.IsSafeDataSet(ds)) {
                    for (int i = 0; (i < ds.Tables[0].Rows.Count); i = (i + 1)) {
                        OptionInstance obj = new OptionInstance();
                        obj.Fill(ds.Tables[0].Rows[i]);
                        if ((obj != null)) {
                            collection.Add(obj);
                        }
                    }
                }
                return collection;
            }
            catch (System.Exception ) {
                throw;
            }
            finally {
                if ((dbo != null)) {
                    dbo.Dispose();
                }
            }
        }
        
        public static OptionInstanceCollection GetAll() {
            IrisGenerator.Dal.OptionInstance dbo = null;
            try {
                dbo = new IrisGenerator.Dal.OptionInstance();
                System.Data.DataSet ds = dbo.OPTION_INSTANCE_Select_All();
                OptionInstanceCollection collection = new OptionInstanceCollection();
                if (GlobalTools.IsSafeDataSet(ds)) {
                    for (int i = 0; (i < ds.Tables[0].Rows.Count); i = (i + 1)) {
                        OptionInstance obj = new OptionInstance();
                        obj.Fill(ds.Tables[0].Rows[i]);
                        if ((obj != null)) {
                            collection.Add(obj);
                        }
                    }
                }
                return collection;
            }
            catch (System.Exception ) {
                throw;
            }
            finally {
                if ((dbo != null)) {
                    dbo.Dispose();
                }
            }
        }
        
        public static OptionInstance Load(System.Nullable<System.Guid> OPT_INS_ID) {
            IrisGenerator.Dal.OptionInstance dbo = null;
            try {
                dbo = new IrisGenerator.Dal.OptionInstance();
                System.Data.DataSet ds = dbo.OPTION_INSTANCE_Select_One(OPT_INS_ID);
                OptionInstance obj = null;
                if (GlobalTools.IsSafeDataSet(ds)) {
                    if ((ds.Tables[0].Rows.Count > 0)) {
                        obj = new OptionInstance();
                        obj.Fill(ds.Tables[0].Rows[0]);
                    }
                }
                return obj;
            }
            catch (System.Exception ) {
                throw;
            }
            finally {
                if ((dbo != null)) {
                    dbo.Dispose();
                }
            }
        }
        
        public virtual void Load() {
            IrisGenerator.Dal.OptionInstance dbo = null;
            try {
                dbo = new IrisGenerator.Dal.OptionInstance();
                System.Data.DataSet ds = dbo.OPTION_INSTANCE_Select_One(this.OptInsId);
                if (GlobalTools.IsSafeDataSet(ds)) {
                    if ((ds.Tables[0].Rows.Count > 0)) {
                        this.Fill(ds.Tables[0].Rows[0]);
                    }
                }
            }
            catch (System.Exception ) {
                throw;
            }
            finally {
                if ((dbo != null)) {
                    dbo.Dispose();
                }
            }
        }
        
        public virtual void Insert() {
            IrisGenerator.Dal.OptionInstance dbo = null;
            try {
                dbo = new IrisGenerator.Dal.OptionInstance();
                dbo.OPTION_INSTANCE_Insert(this._optId, this._modInsId, this.OptInsValue);
            }
            catch (System.Exception ) {
                throw;
            }
            finally {
                if ((dbo != null)) {
                    dbo.Dispose();
                }
            }
        }
        
        public virtual void Delete() {
            IrisGenerator.Dal.OptionInstance dbo = null;
            try {
                dbo = new IrisGenerator.Dal.OptionInstance();
                dbo.OPTION_INSTANCE_Delete(this.OptInsId);
            }
            catch (System.Exception ) {
                throw;
            }
            finally {
                if ((dbo != null)) {
                    dbo.Dispose();
                }
            }
        }
        
        public virtual void Update() {
            IrisGenerator.Dal.OptionInstance dbo = null;
            try {
                dbo = new IrisGenerator.Dal.OptionInstance();
                dbo.OPTION_INSTANCE_Update(this.OptInsId, this._optId, this._modInsId, this.OptInsValue);
            }
            catch (System.Exception ) {
                throw;
            }
            finally {
                if ((dbo != null)) {
                    dbo.Dispose();
                }
            }
        }
    }
}
